﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ContactApplication.aspx.cs" Inherits="CRMWeb.Pages.Contact.ContactApplication" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <table id="dgAppLoan" style="width: auto;" autorowheight="true" rownumbers="true" fitcolumns="true" singleselect="true">
        <thead>
            <tr>
                <th field="app_id" hidden="true">Application-ID</th>
                <th field="cdate" width="30" sortable="true">Date Created</th>
                <th field="age" data-options="formatter:calculateAge" width="25" sortable="true">Age</th>
                <th field="DesiredAmount" width="20" data-options="formatter:ReplaceNumberWithCommas" sortable="true">Desired Amount</th>
                <th field="OfferedAmount" width="20" data-options="formatter:ReplaceNumberWithCommas" sortable="true">Offered Amount</th>
                <th field="app_result" width="45" sortable="true">Last Result</th>
                <th field="EditDate" width="30" sortable="true">Edit Date</th>
                <th field="PurposeSummary" width="20">Product</th>
                <th field="comesfrom" width="20">Came From</th>
            </tr>
        </thead>
    </table>
    <script type="text/javascript">
        var lastsortCol = '';
        function ReplaceNumberWithCommas(yourNumber) {
            if (yourNumber != null) {
                //Seperates the components of the number
                var components = yourNumber.toString().split(".");
                //Comma-fies the first part
                components[0] = components[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
                //Combines the two sections
                return "$" + components.join(".");
            }
        }
        function calculateAge(value, row) {
            var date = null;
            if (value == null)
                date = new Date();
            else
                date = new Date(value);
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return getAge((m < 10 ? ('0' + m) : m) + '/' + (d < 10 ? ('0' + d) : d) + '/' + y);
        }

        $('#dgAppLoan').datagrid({
            url: '/WebServices/ApplicationContact.ashx?method=GetAppLoanRecord&ContactID=' + getQuerystring('contact_id', 0) + '&sortText=cdate1 Desc',
            onDblClickRow: function (index, rowdata) {
                if (rowdata.PurposeSummary == "SACC")
                    window.location.href = "/Pages/Application/ApplicationDetailSACC.aspx?app_id=" + rowdata.app_id + "&type=" + rowdata.PurposeSummary;
                else
                    window.location.href = "/Pages/Application/ApplicationDetail.aspx?app_id=" + rowdata.app_id + "&type=" + rowdata.PurposeSummary;
            },
            onSortColumn: function (sort, order) {
                if (sort === 'cdate' || sort === 'EditDate')
                    sort = sort + '1';

                $('#dgAppLoan').datagrid({
                    url: '/WebServices/ApplicationContact.ashx?method=GetAppLoanRecord&ContactID=' + getQuerystring('contact_id', 0) + '&sortText=' + sort + ' ' + order
                });
            }
        });

    </script>
</body>
</html>
